<template>
	<div>
		<p style="margin: 10px 0;font-size: 18px;">航班选择</p>
		<el-table
			:data="list"
			border
			stripe
		>
			<el-table-column
				type="index"
				width="50"
			/>
			<el-table-column
				prop="aircraftSequence"
				label="飞机序列号"
			/>
			<el-table-column label="航班详情">
				<template slot-scope="scope">
					<el-popover
						placement="right"
						trigger="click"
					>
						<el-timeline>
							<el-timeline-item>
								<el-card>
									<h4>
										出发地：{{scope.row.startCity+":"+scope.row.startAirport}}
									</h4>
									<h5>
										出发时间：{{scope.row.startTime}}
									</h5>
								</el-card>
							</el-timeline-item>
							<el-timeline-item>
								<el-card>
									<h4>
										到达地：{{scope.row.reachCity+":"+scope.row.reachAirport}}
									</h4>
									<h5>
										到达时间：{{scope.row.reachTime}}
									</h5>
								</el-card>
							</el-timeline-item>
						</el-timeline>
						<el-button slot="reference">查看详情</el-button>
					</el-popover>
				</template>
			</el-table-column>
			<el-table-column
				prop="economyClassPrice"
				label="经济舱价格"
			/>
			<el-table-column
				prop="businessClassPrice"
				label="头等舱价格"
			/>
			<el-table-column
				prop="ticketsNum"
				label="机票数量"
			/>
			<el-table-column label="机票购买">
				<template slot-scope="scope">
					<el-button
						@click="buy(scope.row.id)"
						type="success"
						plain
						style="margin-left: 16px;"
					>
						购买
					</el-button>
				</template>
			</el-table-column>

		</el-table>

	</div>

</template>

<script>
	export default {
		// filters: {
		// 	FormatDateTime(value) {
		// 		let date = new Date(value);
		// 		let yy = date.getFullYear();
		// 		let MM = date.getMonth() + 1;
		// 		MM = MM < 10 ? "0" + MM : MM;
		// 		let dd = date.getDate();
		// 		dd = dd < 10 ? "0" + dd : dd;
		// 		let hh = date.getHours();
		// 		hh = hh < 10 ? "0" + hh : hh;
		// 		let mm = date.getMinutes();
		// 		mm = mm < 10 ? "0" + mm : mm;
		// 		return yy + "-" + MM + "-" + dd + " " + hh + ":" + mm;
		// 	}
		// },
		data() {
			return {
				list: null,
				list3: null,

			};
		},

		methods: {
			fetchDataList() {
				const startCityP = this.$route.query.startCity;
				const reachCityP = this.$route.query.reachCity;
				const startTimeP = this.$route.query.startTime;
				const reachTimeP = this.$route.query.reachTime;

				const airInfo = { startCity: startCityP, reachCity: reachCityP, startTime: startTimeP, reachTime: reachTimeP };
				this.$http.post("http://localhost/api/core/aircraftInfo/search", airInfo).then(res => {
					if (res.data.code == 0) {
						this.list = res.data.data.aircraftInfo;
					} else {
						this.$message.error("查询失败，请重试");
					}
				})
			},
			buy(id) {
				this.$router.push({
					path: "/starttobuy",
					query: {
						stepId: "1",
						aircraftInfoId: id,
					}
				});
				// this.$http.get("http://localhost/api/core/aircraftInfo/get/" + this.aircraftInfoId).then(response => {
				// 	if (response.data.code == 0) {
				// 		console.log(response.data.data.aircraftInfo);
				// 		this.list3 = response.data.data.aircraftInfo;
				// 	}
				// })
				// eventBus.$emit("bus", this.list3);
				location.reload();
			}
		},
		created() {
			this.fetchDataList();
		},
	};
</script>